using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace AppManagement.MainManagers
{
	#region using
	using DevComponents.DotNetBar;
	using AppManagement.Models;
	using AppManagement.Repositories;
	using AppManagement.Helpers;
	using System.Data;
	using System.Drawing;
	using System.IO;
	#endregion

	public partial class FrmCapNhatChiTietKHDT : Office2007Form
	{
		public EventHandler Handler { get; set; }
		private DevComponents.DotNetBar.Controls.TextBoxX txtMaHP;
        private int MaKhoa;

		public FrmCapNhatChiTietKHDT(int makhoa)
		{
			InitializeComponent();
			InitHiddenFields();
            this.MaKhoa = makhoa;
		}

		public void InitHiddenFields()
		{
			txtMaHP = new DevComponents.DotNetBar.Controls.TextBoxX
			{
				Name = "txtMaHP",
				Text = ""
			};
			txtMaHP.Visible = false;
		}

		private void btnChonHocPhan_Click(object sender, EventArgs e)
		{
			FrmQuanLyHocPhan frm = new FrmQuanLyHocPhan(this.MaKhoa.ToString(), true);
			frm.Handler += GetHocPhan;
			frm.ShowDialog();
		}

		public void GetHocPhan(object sender, EventArgs e)
		{
			var eventType = (TransferSimpleDataEvent)e;
			string[] comp = eventType.Data.Split(new char[] { '#' });
			txtMaHP.Text = comp[0];
			txtHocPhan.Text = comp[1];
		}


		private bool ValidateInput(ref string errorText)
		{
			if (txtMaHP.Text == "")
			{
				 errorText = "Vui lòng nhập MaHP";
				return false;
			}
			return true;
		}

		private void btnCapNhat_Click(object sender, EventArgs e)
		{
			var errorText = "";
			if (!ValidateInput(ref errorText))
			{
				MessageBox.Show(errorText, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			TransferDataInfo(this, new TransferSimpleDataEvent(txtMaHP.Text));
		}

		public void TransferDataInfo(object sender, TransferSimpleDataEvent e)
		{
			this.Close();
			this.Handler(this, e);
		}

		private void btnThoat_Click(object sender, EventArgs e)
		{
			this.Close();
		}


	}

}
